
<%@ page contentType="text/html;charset=UTF-8" %>
<html>  
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta name="layout" content="main" />
        <title>在线翻译</title>
        <style>
                textarea{
                    border:1px solid #CCC;
                }
        </style>
        <script type="text/javascript" src="http://www.google.com/jsapi"></script>
        <script type="text/javascript">
            google.load("language", "1");
            function trans(obj) {
                obj.disabled=true;
                var text = document.getElementById('srcText').value;
                google.language.detect(text, function(result) {
                    if (!result.error && result.language) {
                        google.language.translate(text, "", "zh-CN",
                        function(result) {
                            var translated = document.getElementById("desText");
                            obj.disabled=false;
                            if (result.translation) {
                                translated.innerHTML = result.translation;
                            }else{
                                alert("无翻译结果");
                            }
                        });
                    }else{
                        obj.disabled=false;
                        alert(result.error);
                    }
                });
            }
        </script>
    </head>
    <body>
        <div class="nav">
            <span class="menuButton"><g:link class="list" controller="tools" action="toolList">个人实用工具列表</g:link></span>
        </div>
        <div class="body">
            <h1>英文原文：</h1>
            <textarea type="text" id="srcText" rows=15 style="width:98%"></textarea>
            <p>
                <h1>翻译结果：</h1>
                <span id="desText"></span>
            </p>
            <center>
                <button onclick="trans(this)">给我翻译</button>
            </center>
        </div>
    </body>
</html>  
